<?php
namespace Application\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
class IpaddressTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	public function getIp($ipaddress)
    {
		
		$select = $this->tableGateway->getSql()->select()
				->where('ip_address="'.$ipaddress.'"');
		$resultSet = $this->tableGateway->selectWith($select);
        $row = $resultSet->current();
		if (!$row) {
            throw new \Exception("Could not find row $ipaddress");
        }
        return $row;
    }
	public function saveAddress($ipaddress,$cityname,$statename,$countryname)
    {
		$data = array(
			'ip_address' 	  	=> $ipaddress, 	
			'city_name' 		=> $cityname,  		
			'state_name'  		=> $statename, 
			'country_name' 		=> $countryname, 				
		);
		$this->tableGateway->insert($data);
		return $this->tableGateway->lastInsertValue;
    }

}